Skip to content

Fix custom printf/malloc#783

Merged
mateoconlechuga merged 4 commits intomasterfrom
fix_custom_printf_malloc
Apr 18, 2026
Merged

Fix custom printf/malloc#783
mateoconlechuga merged 4 commits intomasterfrom
fix_custom_printf_malloc

Conversation

@ZERICO2005
Copy link
Copy Markdown
Contributor

@ZERICO2005 ZERICO2005 commented Apr 13, 2026

The test for std::terminate was added to make sure that sprintf (used by std::terminate) is linked even if no functions from libnanoprintf.a are directly referenced by lto.s.

#include <ti/screen.h>
#include <ti/getcsc.h>
#include <exception>

int main(void) {
    os_ClrHome();
    os_PutStrFull("before std::terminate");
    while (!os_GetCSC());

    std::terminate();
}

To define a custom malloc/free/realloc, the user must set ALLOCATOR = CUSTOM in the makefile, then they just have to define malloc in one of two ways:

// it is recommended but not strictly necessary to #include <stdlib.h>
#include <stdlib.h>
void *malloc(size_t size) {
    /* code */
}
	.global	_malloc
	.type	_malloc, @function
_malloc:
	; code
	ret

This does remove support for _custom_malloc/_custom_free/_custom_realloc, but the user can fix it by doing:

	.global	_malloc
	.type	_malloc, @function
_malloc:
	jp _custom_malloc
	.extern _custom_malloc

@ZERICO2005 ZERICO2005 force-pushed the fix_custom_printf_malloc branch from f75cbcd to 6daa4f6 Compare April 13, 2026 21:03
@ZERICO2005 ZERICO2005 marked this pull request as ready for review April 15, 2026 02:45
@mateoconlechuga mateoconlechuga merged commit b8bd9e5 into master Apr 18, 2026
9 checks passed
@mateoconlechuga mateoconlechuga deleted the fix_custom_printf_malloc branch April 18, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

cedev-obj only searches lto.s

2 participants